package com.liao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liao.common.R;
import com.liao.po.Goods;
import com.liao.po.Goodstype;
import com.liao.service.GoodstypeService;
import com.liao.utils.PageUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("goodstype")
public class GoodstypeController {

    @Autowired
    private GoodstypeService goodstypeService;

    /**
     * 根据参数获取用户列表
     */
    @GetMapping("/list")
    @ApiOperation("根据参数获取用户列表")
    //@RequiresPermissions("product:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodstypeService.queryPageByCodition(params);

        return R.success(page);
    }

    @GetMapping("/getType")
    @ApiOperation("根据参数获取用户列表")
    //@RequiresPermissions("product:skuinfo:list")
    public R getType(){
        List<Goodstype> list = goodstypeService.list();
        return R.success(list);
    }

    /**
     * 保存或修改
     */
    @PostMapping("/save")
    public R saveOrUpdate(@RequestBody Goodstype goodstype){
        LocalDateTime creatdate = goodstype.getCreatdate();
        if (creatdate == null){
            goodstype.setCreatdate(LocalDateTime.now());
        }
        goodstype.setUpdatedate(LocalDateTime.now());
        goodstypeService.saveOrUpdate(goodstype);
        return R.success("保存成功");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds){
        goodstypeService.removeByIds(Arrays.asList(skuIds));

        return R.success("删除成功");
    }
}
